package com.sky.controller.user;

import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "用户套餐相关接口")
@Slf4j
@RequestMapping("/user/setmeal")
@RestController("userSetmealController")
public class SetmealContoller {
    @Autowired
    private SetmealService setmealService;
    @Autowired
    private DishService dishService;
    @Cacheable(cacheNames = "setmeal",key = "#categoryId")
    @ApiOperation("根据套餐分类Id查询套餐接口")
    @GetMapping("/list")
    public Result list(Long categoryId){
        log.info("收到categoryId:{}",categoryId);
        List<Setmeal> setmeals =  setmealService.selectByCategoryId(categoryId);
        return Result.success(setmeals);
    }
    @GetMapping("/dish/{id}")
    public Result listDishBySetmealId(@PathVariable Long id){
        List<DishItemVO> vo = dishService.getListBySetmealId(id);
        return Result.success(vo);
    }
}
